<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
  import { departmentListApi } from '@/apis/consult'
  import type { DepartData } from '@/types/consult'
  import { onLoad } from '@dcloudio/uni-app'
  import { computed, ref } from 'vue'
  const departmentLis = ref<DepartData[]>([])
  const getDepartmentList = async () => {
    const res = await departmentListApi()
    departmentLis.value = res
  }
  onLoad(() => {
    getDepartmentList()
  })
  const active = ref(0)
  const change = (index: number) => {
    active.value = index
  }
  const childList = computed(() => {
    return departmentLis.value[active.value]?.child
  })
  const props = defineProps<{
    type: string
    illnessType: string
  }>()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view
        v-for="(item, index) in departmentLis"
        :key="item.id"
        @click="change(index)"
        class="department-item"
        :class="{ active: active === index }"
      >
        {{ item.name }}
      </view>
      <!-- <view class="department-item">外科</view> -->
      <view class="department-item"></view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator
        v-for="item in childList"
        :key="item.id"
        hover-class="none"
        :url="`/subpkg_consult/description/index?type=${props.type}&illnessType=${props.illnessType}&depId=${item.id}`"
        class="department-item"
      >
        <view> {{ item.name }}</view>
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './index.scss';
</style>
